﻿Public Class Frm2ClientesMenu
    Public Sub cargarRegistros(ByVal fila As Integer)
        Try
            Dim accion As New SocioDAO
            'Llenar tabla
            Dim tabla As New DataTable
            tabla = accion.mostrar
            'Comprobar si hay datos
            If Not tabla Is Nothing Then
                'Cargar datos en el grid
                'DGV1.DataSource = tabla
                FormatosGrid.funciones.formatoGrid_Socios(DGV1, tabla)
                'Mostrar datos en los controles
                lblIDSocio.Text = DGV1.Rows(fila).Cells(0).Value
                txtCodigo.Text = DGV1.Rows(fila).Cells(1).Value
                txtNombre.Text = DGV1.Rows(fila).Cells(2).Value
                txtDireccion.Text = DGV1.Rows(fila).Cells(3).Value
                txtDocumento.Text = DGV1.Rows(fila).Cells(4).Value
                txtTelefono.Text = DGV1.Rows(fila).Cells(5).Value
                txtEmail.Text = DGV1.Rows(fila).Cells(6).Value
                txtContacto.Text = DGV1.Rows(fila).Cells(7).Value
                lblTipo.Text = DGV1.Rows(fila).Cells(8).Value
                lblIdTSocio.Text = DGV1.Rows(fila).Cells(9).Value
                'Seleccionar toda la fila
                DGV1.Rows(fila).Selected = True
                DGV1.CurrentCell = DGV1.Rows(fila).Cells(1)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK,
                        MessageBoxIcon.Warning)
        End Try
    End Sub
    Private Sub dgv1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DGV1.CurrentCellChanged
        Try
            If Not DGV1.CurrentCell Is Nothing Then
                With DGV1
                    lblIDSocio.Text = .Rows(.CurrentCell.RowIndex).Cells(0).Value
                    txtCodigo.Text = .Rows(.CurrentCell.RowIndex).Cells(1).Value
                    txtNombre.Text = .Rows(.CurrentCell.RowIndex).Cells(2).Value
                    txtDireccion.Text = .Rows(.CurrentCell.RowIndex).Cells(3).Value
                    txtDocumento.Text = .Rows(.CurrentCell.RowIndex).Cells(4).Value
                    txtTelefono.Text = .Rows(.CurrentCell.RowIndex).Cells(5).Value
                    txtEmail.Text = .Rows(.CurrentCell.RowIndex).Cells(6).Value
                    txtContacto.Text = .Rows(.CurrentCell.RowIndex).Cells(7).Value
                    lblTipo.Text = .Rows(.CurrentCell.RowIndex).Cells(8).Value
                    lblIdTSocio.Text = .Rows(.CurrentCell.RowIndex).Cells(9).Value
                End With
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Advertencia", MessageBoxButtons.OK,
              MessageBoxIcon.Warning)
        End Try
    End Sub
    Private Sub Frm2ClientesMenu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cargarRegistros(0)
        txtCodigo.Enabled = False
        txtNombre.Enabled = False
        txtDireccion.Enabled = False
        txtDocumento.Enabled = False
        txtTelefono.Enabled = False
        txtEmail.Enabled = False
        txtContacto.Enabled = False
    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim dato As New Socio
        Dim accion As New SocioDAO
        Dim resp As DialogResult
        dato.pID = lblIDSocio.Text
        dato.pCod = txtCodigo.Text
        dato.pNombre = txtNombre.Text
        dato.pDirec = txtDireccion.Text
        dato.pDocu = txtDocumento.Text
        dato.pTelefono = txtTelefono.Text
        dato.pEmail = txtEmail.Text
        dato.pContac = txtContacto.Text
        dato.pIdtsocio = lblIdTSocio.Text


        resp = MessageBox.Show("Desea eliminar el registro " & dato.pNombre, "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        If resp = Windows.Forms.DialogResult.Yes Then
            If accion.eliminar(dato) Then
                MessageBox.Show("Registro eliminado", "Borrar", MessageBoxButtons.OK, MessageBoxIcon.Information)
                cargarRegistros(0)
            Else
                MessageBox.Show("No se puede eliminar el registro, contacte al administrador", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim FrmClienteNuevo As New Frm2ClientesNuevos
        FrmClienteNuevo.Show()
        Me.Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Frm2ClientesEditar.Show(Me.lblIDSocio.Text, Me.txtCodigo.Text, Me.txtNombre.Text, Me.txtDireccion.Text,
                                Me.txtDocumento.Text, Me.txtTelefono.Text, Me.txtEmail.Text, Me.txtContacto.Text, Me.lblIdTSocio.Text, Me)
        Me.Close()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Frm2ClientesBuscar.Show()
        Me.Close()

    End Sub
End Class